using UnityEngine;
using System.Collections;

/// \class  gkScrollingParticle
/// \brief  Add a scrolling movement to the particles
[AddComponentMenu("GK/Engine/Game/Scrolling/gkScrollingParticle")]
public class gkScrollingParticle : MonoBehaviour 
{	
	/// The scrolling info
    private gkScrollingInfo m_rScrollingInfo;

    /// \brief  Called just after the game begin to play
    void Start()
    {
	    // Grab the scrolling info
	    m_rScrollingInfo = GameObject.Find("ScrollingInfo").GetComponent<gkScrollingInfo>();
    }
	
	/// \brief  Called after each objects Update
	void LateUpdate() 
	{
		Particle[] rParticles;
		Vector3 f3NewVelocity;
		
		// extract the particles
		rParticles = particleEmitter.particles;
		for (var i = 0; i < rParticles.Length; i++) 
		{
			// Adapt the X velocity to the scrolling velocity
			f3NewVelocity = rParticles[i].velocity;
			f3NewVelocity.x = m_rScrollingInfo.GetScrollingVelocity();
			rParticles[i].velocity = f3NewVelocity;
		}
		// copy them back to the particle system
		particleEmitter.particles = rParticles;
	}
}